<template>
  <div class="container">
    <div class="app-container">
      <!-- 树形组件 el-tree -->
      <el-tree default-expand-all :data="depts" :props="defaultProps">
        <template #default="{ data }">
          <!-- align 垂直方向居中 -->
          <el-row style="width: 100%; height:40px" align="middle" type="flex" justify="space-between">
            <span>{{ data.name }}</span>
            <el-col :span="4">
              <!-- 负责人 -->
              <span class="good-name">{{ data.managerName }}</span>
              <!-- 下拉菜单 -->
              <el-dropdown>
                <span class="el-dropdown-link">
                  操作<i class="el-icon-arrow-down el-icon--right" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>添加子部门</el-dropdown-item>
                  <el-dropdown-item>编辑部门</el-dropdown-item>
                  <el-dropdown-item>删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-col>
          </el-row>

        </template>

      </el-tree>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Department',
  data() {
    return {
      depts: [
        {
          name: '传智教育', // 根节点标签
          managerName: '管理员',
          children: [ // 子节点数组
            { name: '总裁办', managerName: '管理员' },
            { name: '行政部', managerName: '文吉星' },
            { name: '人事部',
              managerName: '紫微星',
              children: [
                { name: '税务核算部', managerName: '太白金星' },
                { name: '税务管理部', managerName: '满天星' },
                { name: '薪资管理部', managerName: '芸芸众星' }
              ]
            }
          ]
        }

      ],
      defaultProps: {
        children: 'children',
        label: 'name' // 标签文本字段
      }
    }
  }
}
</script>
<style scoped lang="scss">
  .app-container {
    padding: 32px 140px;
    font-size: 14px;
  }
  .good-name{
    // margin: 5px;
    width: 60px;
    display: inline-block;
  }
</style>
